<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>SQL JDBC | ElasticSearch 7.7 权威指南中文版</title>
	<meta name="keywords" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <meta name="description" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
	<script>
	var _link = 'sql-jdbc.html';
    </script>
</head>
<body>
<div class="main-container">
    <section id="content">
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/reference/7.7/sql-jdbc.html" rel="nofollow" target="_blank">https://www.elastic.co/guide/en/elasticsearch/reference/7.7/sql-jdbc.html</a>, 原文档版权归 www.elastic.co 所有<br/>本地英文版地址: <a href="../en/sql-jdbc.html" rel="nofollow" target="_blank">../en/sql-jdbc.html</a></div>
                        <!-- start body -->
                  <div class="page_header">
<strong>重要</strong>: 此版本不会发布额外的bug修复或文档更新。最新信息请参考 <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html" rel="nofollow">当前版本文档</a>。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch Guide [7.7]</a></span>
»
<span class="breadcrumb-link"><a href="xpack-sql.html">SQL access</a></span>
»
<span class="breadcrumb-node">SQL JDBC</span>
</div>
<div class="navheader">
<span class="prev">
<a href="sql-cli.html">« SQL CLI</a>
</span>
<span class="next">
<a href="_api_usage.html">API usage »</a>
</span>
</div>
<div class="chapter xpack">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="sql-jdbc"></a>SQL JDBC<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/sql/endpoints/jdbc.asciidoc">edit</a><a class="xpack_tag" href="https://www.elastic.co/subscriptions"></a>
</h2>
</div></div></div>
<p>Elasticsearch’s SQL jdbc driver is a rich, fully featured JDBC driver for Elasticsearch.
It is Type 4 driver, meaning it is a platform independent, stand-alone, Direct to Database,
pure Java driver that converts JDBC calls to Elasticsearch SQL.</p>
<h3>
<a id="sql-jdbc-installation"></a>Installation<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/sql/endpoints/jdbc.asciidoc">edit</a>
</h3>
<p>The JDBC driver can be obtained from:</p>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
Dedicated page
</span>
</dt>
<dd>
<a href="https://www.elastic.co/downloads/jdbc-client" class="ulink" target="_top">elastic.co</a> provides links, typically for manual downloads.
</dd>
<dt>
<span class="term">
Maven dependency
</span>
</dt>
<dd>
<a href="http://maven.apache.org/" class="ulink" target="_top">Maven</a>-compatible tools can retrieve it automatically as a dependency:
</dd>
</dl>
</div>
<div class="pre_wrapper lang-xml">
<pre class="programlisting prettyprint lang-xml">&lt;dependency&gt;
  &lt;groupId&gt;org.elasticsearch.plugin&lt;/groupId&gt;
  &lt;artifactId&gt;x-pack-sql-jdbc&lt;/artifactId&gt;
  &lt;version&gt;7.7.1&lt;/version&gt;
&lt;/dependency&gt;</pre>
</div>
<p>from <code class="literal">artifacts.elastic.co/maven</code> by adding it to the repositories list:</p>
<div class="pre_wrapper lang-xml">
<pre class="programlisting prettyprint lang-xml">&lt;repositories&gt;
  &lt;repository&gt;
    &lt;id&gt;elastic.co&lt;/id&gt;
    &lt;url&gt;https://artifacts.elastic.co/maven&lt;/url&gt;
  &lt;/repository&gt;
&lt;/repositories&gt;</pre>
</div>
<h3>
<a id="jdbc-setup"></a>Setup<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/sql/endpoints/jdbc.asciidoc">edit</a>
</h3>
<p>The driver main class is <code class="literal">org.elasticsearch.xpack.sql.jdbc.EsDriver</code>.
Note the driver  implements the JDBC 4.0 <code class="literal">Service Provider</code> mechanism meaning it is registered automatically
as long as it is available in the classpath.</p>
<p>Once registered, the driver understands the following syntax as an URL:</p>
<div class="pre_wrapper lang-text">
<pre class="programlisting prettyprint lang-text">jdbc:es://[[http|https]://]?[host[:port]]?/[prefix]?[\?[option=value]&amp;]*</pre>
</div>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">jdbc:es://</code>
</span>
</dt>
<dd>
Prefix. Mandatory.
</dd>
<dt>
<span class="term">
<code class="literal">[[http|https]://]</code>
</span>
</dt>
<dd>
Type of HTTP connection to make. Possible values are
<code class="literal">http</code> (default) or <code class="literal">https</code>. Optional.
</dd>
<dt>
<span class="term">
<code class="literal">[host[:port]]</code>
</span>
</dt>
<dd>
Host (<code class="literal">localhost</code> by default) and port (<code class="literal">9200</code> by default).
Optional.
</dd>
<dt>
<span class="term">
<code class="literal">[prefix]</code>
</span>
</dt>
<dd>
Prefix (empty by default). Typically used when hosting Elasticsearch under
a certain path. Optional.
</dd>
<dt>
<span class="term">
<code class="literal">[option=value]</code>
</span>
</dt>
<dd>
Properties for the JDBC driver. Empty by default.
Optional.
</dd>
</dl>
</div>
<p>The driver recognized the following properties:</p>
<h5>
<a id="jdbc-cfg"></a>Essential<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/sql/endpoints/jdbc.asciidoc">edit</a>
</h5>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">timezone</code> (default JVM timezone)
</span>
</dt>
<dd>
Timezone used by the driver <em>per connection</em> indicated by its <code class="literal">ID</code>.
<span class="strong strong"><strong>Highly</strong></span> recommended to set it (to, say, <code class="literal">UTC</code>) as the JVM timezone can vary, is global for the entire JVM and can’t be changed easily when running under a security manager.
</dd>
</dl>
</div>
<h5>
<a id="jdbc-cfg-network"></a>Network<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/sql/endpoints/jdbc.asciidoc">edit</a>
</h5>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">connect.timeout</code> (default 30s)
</span>
</dt>
<dd>
Connection timeout (in seconds). That is the maximum amount of time waiting to make a connection to the server.
</dd>
<dt>
<span class="term">
<code class="literal">network.timeout</code> (default 60s)
</span>
</dt>
<dd>
Network timeout (in seconds). That is the maximum amount of time waiting for the network.
</dd>
<dt>
<span class="term">
<code class="literal">page.timeout</code> (default 45s)
</span>
</dt>
<dd>
Page timeout (in seconds). That is the maximum amount of time waiting for a page.
</dd>
<dt>
<span class="term">
<code class="literal">page.size</code> (default 1000)
</span>
</dt>
<dd>
Page size (in entries). The number of results returned per page by the server.
</dd>
<dt>
<span class="term">
<code class="literal">query.timeout</code> (default 90s)
</span>
</dt>
<dd>
Query timeout (in seconds). That is the maximum amount of time waiting for a query to return.
</dd>
</dl>
</div>
<h4>
<a id="jdbc-cfg-auth"></a>Basic Authentication<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/sql/endpoints/jdbc.asciidoc">edit</a>
</h4>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">user</code>
</span>
</dt>
<dd>
Basic Authentication user name
</dd>
<dt>
<span class="term">
<code class="literal">password</code>
</span>
</dt>
<dd>
Basic Authentication password
</dd>
</dl>
</div>
<h4>
<a id="jdbc-cfg-ssl"></a>SSL<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/sql/endpoints/jdbc.asciidoc">edit</a>
</h4>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">ssl</code> (default false)
</span>
</dt>
<dd>
Enable SSL
</dd>
<dt>
<span class="term">
<code class="literal">ssl.keystore.location</code>
</span>
</dt>
<dd>
key store (if used) location
</dd>
<dt>
<span class="term">
<code class="literal">ssl.keystore.pass</code>
</span>
</dt>
<dd>
key store password
</dd>
<dt>
<span class="term">
<code class="literal">ssl.keystore.type</code> (default <code class="literal">JKS</code>)
</span>
</dt>
<dd>
key store type. <code class="literal">PKCS12</code> is a common, alternative format
</dd>
<dt>
<span class="term">
<code class="literal">ssl.truststore.location</code>
</span>
</dt>
<dd>
trust store location
</dd>
<dt>
<span class="term">
<code class="literal">ssl.truststore.pass</code>
</span>
</dt>
<dd>
trust store password
</dd>
<dt>
<span class="term">
<code class="literal">ssl.truststore.type</code> (default <code class="literal">JKS</code>)
</span>
</dt>
<dd>
trust store type. <code class="literal">PKCS12</code> is a common, alternative format
</dd>
<dt>
<span class="term">
<code class="literal">ssl.protocol</code>(default <code class="literal">TLS</code>)
</span>
</dt>
<dd>
SSL protocol to be used
</dd>
</dl>
</div>
<h4>
<a id="_proxy"></a>Proxy<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/sql/endpoints/jdbc.asciidoc">edit</a>
</h4>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">proxy.http</code>
</span>
</dt>
<dd>
Http proxy host name
</dd>
<dt>
<span class="term">
<code class="literal">proxy.socks</code>
</span>
</dt>
<dd>
SOCKS proxy host name
</dd>
</dl>
</div>
<h4>
<a id="_mapping"></a>Mapping<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/sql/endpoints/jdbc.asciidoc">edit</a>
</h4>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">field.multi.value.leniency</code> (default <code class="literal">true</code>)
</span>
</dt>
<dd>
Whether to be lenient and return the first value (without any guarantees of what that
will be - typically the first in natural ascending order) for fields with multiple values (true) or throw an exception.
</dd>
</dl>
</div>
<h4>
<a id="_index"></a>Index<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/sql/endpoints/jdbc.asciidoc">edit</a>
</h4>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">index.include.frozen</code> (default <code class="literal">false</code>)
</span>
</dt>
<dd>
Whether to include <a class="xref" href="frozen-indices.html" title="Frozen indices">frozen-indices</a> in the query execution or not (default).
</dd>
</dl>
</div>
<h4>
<a id="_additional"></a>Additional<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/sql/endpoints/jdbc.asciidoc">edit</a>
</h4>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">validate.properties</code> (default true)
</span>
</dt>
<dd>
If disabled, it will ignore any misspellings or unrecognizable properties. When enabled, an exception
will be thrown if the provided property cannot be recognized.
</dd>
</dl>
</div>
<p>To put all of it together, the following URL:</p>
<div class="pre_wrapper lang-text">
<pre class="programlisting prettyprint lang-text">jdbc:es://http://server:3456/?timezone=UTC&amp;page.size=250</pre>
</div>
<p>Opens up a Elasticsearch SQL connection to <code class="literal">server</code> on port <code class="literal">3456</code>, setting the JDBC connection timezone to <code class="literal">UTC</code> and its pagesize to <code class="literal">250</code> entries.</p>

</div>
<div class="navfooter">
<span class="prev">
<a href="sql-cli.html">« SQL CLI</a>
</span>
<span class="next">
<a href="_api_usage.html">API usage »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>